package com.wswy.wzcx.jpush

import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.content.ContextWrapper
import android.graphics.Color
import android.os.Build
import android.support.annotation.RequiresApi
import com.wswy.wzcx.R

/**
 * Created by wangduheng26 on 2018/3/16.
 * wangduheng26@gmail.com
 */
@RequiresApi(Build.VERSION_CODES.O)
internal class NotificationHelperKF(ctx: Context): ContextWrapper(ctx){
    private val manager : NotificationManager by lazy{
        getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
    }
    init {
        val chan1=NotificationChannel(PRIMARY_CHANNEL,getString(R.string.noti_channel_default),NotificationManager.IMPORTANCE_DEFAULT)
        chan1.lightColor=Color.BLUE
        chan1.lockscreenVisibility=Notification.VISIBILITY_PRIVATE
        manager.createNotificationChannel(chan1)

        val chan2=NotificationChannel(SECONDARY_CHANNEL,getString(R.string.noti_channel_second),NotificationManager.IMPORTANCE_DEFAULT)
        chan2.lightColor=Color.GREEN
        chan2.lockscreenVisibility=Notification.VISIBILITY_PRIVATE
        manager.createNotificationChannel(chan2)
    }


    fun getNotifitionByChan1(title:String,body:String):Notification.Builder{
        return Notification.Builder(applicationContext, PRIMARY_CHANNEL)
                .setContentTitle(title)
                .setContentText(body)
                .setSmallIcon(0)
                .setAutoCancel(true)
    }
    fun getNotifitionByChan2(title:String,body:String):Notification.Builder{
        return Notification.Builder(applicationContext, SECONDARY_CHANNEL)
                .setContentTitle(title)
                .setContentText(body)
                .setSmallIcon(smallIcon)
                .setAutoCancel(true)
    }
    private val smallIcon:Int
        get()=android.R.drawable.stat_notify_chat

    companion object {
        val PRIMARY_CHANNEL="primary"
        val SECONDARY_CHANNEL="secondary"
    }
}